package com.king.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.king.service.*;
import com.king.shiro.AccountProfile;
import org.apache.shiro.SecurityUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    MPostService mPostService;

    @Autowired
    MCommentService mCommentService;

    @Autowired
    MUserService mUserService;

    @Autowired
    MUserCollectionService mUserCollectionService;

    @Autowired
    MUserMessageService mUserMessageService;

    @Autowired
    MCategoryService mCategoryService;

    @Autowired
    WebSocketService webSocketService;

    @Autowired
    SearchService searchService;

    @Autowired
    AmqpTemplate amqpTemplate;

    @Autowired
    ChatService chatService;

    /**
     * 获取分页信息
     *
     * @return
     */
    Page getPage() {
        int pageNum = ServletRequestUtils.getIntParameter(request, "pn", 1);//request.getParameter("pn");//做不到有默认值
        int pageSize = ServletRequestUtils.getIntParameter(request, "size", 2);//request.getParameter("pn");//做不到有默认值
        return new Page(pageNum, pageSize);
    }

    AccountProfile getProfile() {
        return (AccountProfile) SecurityUtils.getSubject().getPrincipal();
    }

    long getProfileId() {
        return getProfile().getId();
    }
}
